package com.example.gradletest;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.arouter_annatation.ARouter;
import com.example.arouter_annatation.ARouterBean;
import com.example.arouter_api.ARouterLoadGroup;
import com.example.arouter_api.ARouterLoadPath;
import com.example.gradletest.test.ARouter$$Group$$Order;
import com.example.gradletest.test.ARouter$$Group$$User;
import com.example.orderapplication.ARouterGroupOrder;
import com.example.userapplication.ARouterGroupUser;

import java.util.Map;

import androidx.appcompat.app.AppCompatActivity;

@ARouter(path = "App/MainActivity",gourp = "App")
public class MainActivity extends AppCompatActivity {
    private TextView tvUser;
    private TextView tvOrder;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvUser = (TextView) findViewById(R.id.tv_user);
        tvOrder = (TextView) findViewById(R.id.tv_order);
        tvUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取组
                ARouterLoadGroup group = new ARouterGroupUser();
                Map<String,  Class<?extends ARouterLoadPath>> map1 = group.loadGroup();

                Class<?extends ARouterLoadPath> clazz = map1.get("User");

                try {
                    ARouterLoadPath  path = clazz.newInstance();
                    //获取path
                    Map<String, ARouterBean> map2 = path.loadPath();
                    ARouterBean bean = map2.get("User/UserActivity");
                    Intent intent = new Intent(MainActivity.this, bean.getClazz());
                    intent.putExtra("User","Admin");
                    startActivity(intent);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                }




            }
        });
        tvOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取组
                ARouterLoadGroup group = new ARouterGroupOrder();
                Map<String, Class<?extends ARouterLoadPath>> map1 = group.loadGroup();
                Class<?extends ARouterLoadPath> clazz = map1.get("Order");

                try {
                    ARouterLoadPath path = clazz.newInstance();
                    //获取path

                    Map<String, ARouterBean> map2 = path.loadPath();
                    ARouterBean bean = map2.get("Order/OrderActivity");
                    Intent intent = new Intent(MainActivity.this, bean.getClazz());
                    intent.putExtra("Order","123456");
                    startActivity(intent);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                }


            }
        });
    }
}
